home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
parcs
/
parcs.lha
/
sample
/
parse.parcs
< prev
next >
Wrap
Text File
|
1992-06-08
|
1KB
|
56 lines
#priority vp(0.5,0,0) 0
#priority np(0.5,0,0) 0
#priority pp(0.3,0,0) 0
analyze(X,Z) :- lex(X,Y),parse(Y,Z).
sanalyze(X,Z) :- lex(X,Y);parse(Y,Z)./* sequential version of analyze */
lex([],[]).
lex([t,o|X],[to|Y]) :- lex(X,Y).
lex([t,h,i,s|X],[this|Y]) :- lex(X,Y).
lex([h,e|X],[he|Y]) :- lex(X,Y).
lex([k,e,n|X],[ken|Y]) :- lex(X,Y).
lex([p,e,n|X],[pen|Y]) :- lex(X,Y).
lex([m,a,n|X],[man|Y]) :- lex(X,Y).
lex([w,i,t,h|X],[with|Y]) :- lex(X,Y).
lex([a|X],[a|Y]) :- lex(X,Y).
lex([t,h,e|X],[the|Y]) :- lex(X,Y).
lex([i,s|X],[is|Y]) :- lex(X,Y).
lex([h,a,s|X],[has|Y]) :- lex(X,Y).
parse(Sentence,Ptree) :- s(Sentence,[],Ptree).
s(X,Y,s(NP,VP)) :- np(X,Z,NP),vp(Z,Y,VP).
vp(X,Y,vp(V)) :- v(X,Y,V).
vp(X,Y,vp(V,NP)) :- v(X,Z,V),np(Z,Y,NP).
vp(X,Y,vp(VP,PP)) :- vp(X,Z,VP),pp(Z,Y,PP).
np(X,Y,np(N)) :- n(X,Y,N).
np(X,Y,np(D,NP)) :- d(X,Z,D),np(Z,Y,NP).
np(X,Y,np(A,NP)) :- a(X,Z,A),np(Z,Y,NP).
np(X,Y,np(NP,PP)) :- np(X,Z,NP),pp(Z,Y,PP).
pp(X,Y,pp(P,NP)) :- p(X,Z,P),np(Z,Y,NP).
n([he|X],X,n(he)).
n([this|X],X,n(this)).
n([pen|X],X,n(pen)).
np([ken|X],X,np(ken)).
n([man|X],X,n(man)).
v([is|X],X,v(is)).
v([has|X],X,v(has)).
a([black|X],X,a(black)).
a([this|X],X,a(this)).
p([with|X],X,p(with)).
p([to|X],X,p(to)).
d([a|X],X,d(a)).
d([the|X],X,d(the)).
/*
:-analyze([t,X,i,s,i,s,a,Y,e,n],Z).
*/